package com.manage.user.service;

import com.manage.user.dao.UserMapper;
import com.manage.user.dao.UserRepository;
import com.manage.user.entity.User;
import com.manage.utils.Criteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author Fitch
 */
@Service
public class UserServiceImpl implements UserService{

    @Autowired
    private UserRepository userRepository;
    @Autowired
    private  UserMapper userMapper;

    @Override
    public User getById(Long id) {
        return this.userRepository.getById(id);
    }

    @Override
    public List<User> listUser(Criteria criteria) {
        return this.userMapper.listUser(criteria);
    }

    @Override
    public User saveUser(User user) {
        Date date = new Date();
        user.setCreateTime(date);
        user.setIsValid(Long.valueOf("1"));
        user=this.userRepository.save(user);
        return user;
    }

    @Override
    public List<User> getByUserName(String userName) {
        return this.userRepository.findAllByUserName(userName);
    }
}
